package cn.udrm.water.base.v1.waterdelivery.entities;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedEntityGraphs;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import org.hibernate.annotations.GenericGenerator;

import cn.udrm.water.base.v1.commons.enums.CanalSystemFunctionEnum;
import cn.udrm.water.base.v1.commons.enums.CanalSystemTypeEnum;
import cn.udrm.water.base.v1.waterdistribute.entities.WaterGate;

/**
 * 渠道实体
 * 渠道具有严格（不一定）的层级关系：总干渠、干渠、支渠、斗渠、农渠
 * @author liukang
 * @date 2018年11月7日
 */
@Getter
@Setter
@Entity(name="CanalSystem")
@Table(name="T_CANAL_SYSTEM")
@NamedEntityGraphs({
	@NamedEntityGraph(name="CanalSystem.all",
			attributeNodes={
			@NamedAttributeNode("canalSystemSections"),
			@NamedAttributeNode("canalSystemSubSections"),
			@NamedAttributeNode("drops"),
			@NamedAttributeNode("invertedSiphons"),
			@NamedAttributeNode("pumpingStations"),
			@NamedAttributeNode("sluices"),
			@NamedAttributeNode("steepSlopes"),
			@NamedAttributeNode("tunnels"),
			@NamedAttributeNode("waterGates"),
			@NamedAttributeNode("childrens"),
			@NamedAttributeNode("canalSystemExt"),
	}), @NamedEntityGraph(name="CanalSystem.canalSystemSections", attributeNodes={
			@NamedAttributeNode("canalSystemSections")
	}), @NamedEntityGraph(name="CanalSystem.canalSystemSubSections", attributeNodes={
			@NamedAttributeNode("canalSystemSubSections")
	}), @NamedEntityGraph(name="CanalSystem.drops", attributeNodes={
			@NamedAttributeNode("drops")
	}), @NamedEntityGraph(name="CanalSystem.invertedSiphons", attributeNodes={
			@NamedAttributeNode("invertedSiphons")
	}), @NamedEntityGraph(name="CanalSystem.pumpingStations", attributeNodes={
			@NamedAttributeNode("pumpingStations")
	}), @NamedEntityGraph(name="CanalSystem.sluices", attributeNodes={
			@NamedAttributeNode("sluices")
	}), @NamedEntityGraph(name="CanalSystem.steepSlopes", attributeNodes={
			@NamedAttributeNode("steepSlopes")
	}), @NamedEntityGraph(name="CanalSystem.tunnels", attributeNodes={
			@NamedAttributeNode("tunnels")
	}), @NamedEntityGraph(name="CanalSystem.waterGates", attributeNodes={
			@NamedAttributeNode("waterGates")
	}), @NamedEntityGraph(name="CanalSystem.childrens", attributeNodes={
			@NamedAttributeNode("childrens")
	}), @NamedEntityGraph(name="CanalSystem.canalSystemExt", attributeNodes={
			@NamedAttributeNode("canalSystemExt")
	})
})
@NoArgsConstructor
public class CanalSystem {

	@Id
	@GenericGenerator(name="idGenerator", strategy="uuid")
	@GeneratedValue(generator="idGenerator")
	@Column(name="ID")
	private String id;
	/*
	 * 系统编码
	 */
	@Column(name="ENTITY_CODE")
	private String entityCode;
	@Column(name="CREATE_DATE")
	private Date createDate;
	@Column(name="PERSON_GUID")
	private String personGuid;
	@Column(name="PERSON_NAME")
	private String personName;
	@Column(name="CREATE_TIME")
	private Date createTime;
	/*
	 * 桩号
	 */
	@Column(name="MILEAGE")
	private String mileage;
	/*
	 * 名称
	 */
	@Column(name="NAME")
	private String name;
	/*
	 * 渠道长度
	 */
	@Column(name="CANAL_SYSTEM_LEN")
	private Float canalSystemLen;
	/*
	 * 渠道坡度
	 */
	@Column(name="SLOPE")
	private Float slope;
	/*
	 * 渠道设计流量
	 */
	@Column(name="DESIGN_FLOW")
	private Float designFlow;
	/*
	 * 渠道最大流量
	 */
	@Column(name="MAX_FLOW")
	private Float maxFlow;
	/*
	 * 渠道糙率
	 */
	@Column(name="ROUGHNESS")
	private Float roughness;
	/*
	 * 渠道控制面积
	 */
	@Column(name="CONTROL_IRRIGATION_AREA")
	private Double controlIrrigationArea;
	/*
	 * 渠道水利用系数
	 */
	@Column(name="UTILIZATION_FACTOR")
	private Double utilizationFactor;
	/*
	 * 备注
	 */
	@Column(name="INFO_REMARKS", length=2018)
	private String infoRemarks;
	/*
	 * 渠道功能
	 * 渠道或者排水沟
	 */
	@Enumerated(EnumType.STRING)
	@Column(name="CANAL_SYSTEM_FUNCTION")
	private CanalSystemFunctionEnum canalSystemFunction;
	/*
	 * 渠道类型
	 * 干支斗农毛
	 */
	@Enumerated(EnumType.STRING)
	@Column(name="CANAL_SYSTEM_TYPE")
	private CanalSystemTypeEnum canalSystemType;
	
	/*
	 * 以下为渠道与其附属建筑物的关系
	 * 1、渠道断面
	 * 2、渠道分段
	 * 3、跌水
	 * 4、倒虹吸
	 * 5、扬水站
	 * 6、渡槽
	 * 7、陡坡
	 * 8、隧洞
	 * 9、闸门
	 */
	@OneToMany(mappedBy="canalSystem")
	private List<CanalSystemSection> canalSystemSections;
	@OneToMany(mappedBy="canalSystem")
	private List<CanalSystemSubSection> canalSystemSubSections;
	@OneToMany(mappedBy="canalSystem")
	private List<Drop> drops;
	@OneToMany(mappedBy="canalSystem")
	private List<InvertedSiphon> invertedSiphons;
	@OneToMany(mappedBy="canalSystem")
	private List<PumpingStation> pumpingStations;
	@OneToMany(mappedBy="canalSystem")
	private List<Sluice> sluices;
	@OneToMany(mappedBy="canalSystem")
	private List<SteepSlope> steepSlopes;
	@OneToMany(mappedBy="canalSystem")
	private List<Tunnel> tunnels;
	@OneToMany(mappedBy="canalSystem")
	private List<WaterGate> waterGates;
	/*
	 * 渠道自关联
	 */
	@ManyToOne(optional=true)
	@JoinColumn(name="PARENT_ID")
	private CanalSystem parent;
	@OneToMany(mappedBy="parent")
	private List<CanalSystem> childrens;
	
	/**
	 * 渠道扩展字段表
	 */
	@OneToOne(mappedBy="canalSystem", fetch=FetchType.LAZY)
	private CanalSystemExt canalSystemExt;
	
	public CanalSystem(String id) {
		this.id = id;
	}
}
